Пример #1
0
status_t
PluginManager::CreateReader(Reader** reader, int32* streamCount,
	media_file_format* mff, BDataIO* source)
{
	TRACE("PluginManager::CreateReader enter\n");

	// The wrapper class will present our source in a more useful
	// way, we create an instance which is buffering our reads and
	// writes.
	BMediaIOWrapper* buffered_source = new BMediaIOWrapper(source);
	status_t ret = buffered_source->InitCheck();
	if (ret != B_OK)
		return ret;

	// get list of available readers from the server
	entry_ref refs[MAX_READERS];
	int32 count;

	ret = AddOnManager::GetInstance()->GetReaders(refs, &count,
		MAX_READERS);
	if (ret != B_OK) {
		printf("PluginManager::CreateReader: can't get list of readers: %s\n",
			strerror(ret));
		return ret;
	}

	// try each reader by calling it's Sniff function...
	for (int32 i = 0; i < count; i++) {
		entry_ref ref = refs[i];
		MediaPlugin* plugin = GetPlugin(ref);
		if (plugin == NULL) {
			printf("PluginManager::CreateReader: GetPlugin failed\n");
			return B_ERROR;
		}

		ReaderPlugin* readerPlugin = dynamic_cast<ReaderPlugin*>(plugin);
		if (readerPlugin == NULL) {
			printf("PluginManager::CreateReader: dynamic_cast failed\n");
			PutPlugin(plugin);
			return B_ERROR;
		}

		*reader = readerPlugin->NewReader();
		if (*reader == NULL) {
			printf("PluginManager::CreateReader: NewReader failed\n");
			PutPlugin(plugin);
			return B_ERROR;
		}

		buffered_source->Seek(0, SEEK_SET);
		(*reader)->Setup(buffered_source);
		(*reader)->fMediaPlugin = plugin;

		if ((*reader)->Sniff(streamCount) == B_OK) {
			TRACE("PluginManager::CreateReader: Sniff success "
				"(%ld stream(s))\n", *streamCount);
			(*reader)->GetFileFormatInfo(mff);
			return B_OK;
		}

		DestroyReader(*reader);
		*reader = NULL;
	}

	TRACE("PluginManager::CreateReader leave\n");
	return B_MEDIA_NO_HANDLER;
}
Пример #2
0
status_t
PluginManager::CreateReader(Reader** reader, int32* streamCount,
	media_file_format* mff, BDataIO* source)
{
	TRACE("PluginManager::CreateReader enter\n");

	BPositionIO *seekable_source = dynamic_cast<BPositionIO *>(source);
	if (seekable_source == 0) {
		printf("PluginManager::CreateReader: non-seekable sources not "
			"supported yet\n");
		return B_ERROR;
	}

	// get list of available readers from the server
	entry_ref refs[MAX_READERS];
	int32 count;

	status_t ret = AddOnManager::GetInstance()->GetReaders(refs, &count,
		MAX_READERS);
	if (ret != B_OK) {
		printf("PluginManager::CreateReader: can't get list of readers: %s\n",
			strerror(ret));
		return ret;
	}

	// try each reader by calling it's Sniff function...
	for (int32 i = 0; i < count; i++) {
		entry_ref ref = refs[i];
		MediaPlugin* plugin = GetPlugin(ref);
		if (plugin == NULL) {
			printf("PluginManager::CreateReader: GetPlugin failed\n");
			return B_ERROR;
		}

		ReaderPlugin* readerPlugin = dynamic_cast<ReaderPlugin*>(plugin);
		if (readerPlugin == NULL) {
			printf("PluginManager::CreateReader: dynamic_cast failed\n");
			PutPlugin(plugin);
			return B_ERROR;
		}

		*reader = readerPlugin->NewReader();
		if (*reader == NULL) {
			printf("PluginManager::CreateReader: NewReader failed\n");
			PutPlugin(plugin);
			return B_ERROR;
		}

		seekable_source->Seek(0, SEEK_SET);
		(*reader)->Setup(seekable_source);
		(*reader)->fMediaPlugin = plugin;

		if ((*reader)->Sniff(streamCount) == B_OK) {
			TRACE("PluginManager::CreateReader: Sniff success "
				"(%ld stream(s))\n", *streamCount);
			(*reader)->GetFileFormatInfo(mff);
			return B_OK;
		}

		DestroyReader(*reader);
		*reader = NULL;
	}

	TRACE("PluginManager::CreateReader leave\n");
	return B_MEDIA_NO_HANDLER;
}
Пример #3
0
int
main(int argc, char *argv[])
{
	if (argc < 2) {
		// missing argument
		char *name = strrchr(argv[0], '/');
		name = name ? name + 1 : argv[0];
		fprintf(stderr, "usage: %s <media-file>\n", name);
		return -1;
	}

	TRACE("\n\n");
	
	TRACE("main: creating plugin...\n");

	MediaPlugin *plugin = instantiate_plugin();

	TRACE("main: creating reader...\n");
	
	ReaderPlugin *readerplugin;
	readerplugin = dynamic_cast<ReaderPlugin *>(plugin);
	
	Reader *reader = readerplugin->NewReader();
	
	TRACE("main: opening source file...\n");

	BDataIO *source = new BFile(argv[1], B_READ_ONLY);

	TRACE("main: calling setup...\n");

	reader->Setup(source);

	TRACE("main: creating ...\n");

	TRACE("main: copyright: \"%s\"\n", reader->Copyright());

	status_t status;
	int32 streamCount;

	status = reader->Sniff(&streamCount);
	if (status != B_OK) {
		TRACE("main: Sniff() failed with error %lx (%s)\n", status, strerror(status));
		goto err;
	}

	TRACE("main: Sniff() found %ld streams\n", streamCount);

	for (int i = 0; i < streamCount; i++) {
		TRACE("main: calling AllocateCookie(stream = %d)\n", i);
		status = reader->AllocateCookie(i, &cookies[i]);
		if (status != B_OK) {
			TRACE("main: AllocateCookie(stream = %d) failed with error 0x%lx (%s)\n",
				i, status, strerror(status));
			goto err;
		}
	}

	for (int i = 0; i < streamCount; i++) {
		TRACE("main: calling GetStreamInfo(stream = %d)\n", i);
		int64 frameCount;
		bigtime_t duration;
		media_format format;
		const void *infoBuffer;
		size_t infoSize;
		status = reader->GetStreamInfo(cookies[i], &frameCount, &duration, &format,
			&infoBuffer, &infoSize);
		if (status != B_OK) {
			TRACE("main: GetStreamInfo(stream = %d) failed with error 0x%lx (%s)\n",
				i, status, strerror(status));
			goto err;
		}
		TRACE("main: GetStreamInfo(stream = %d) result: %Ld frames, %.6f sec\n",
			i, frameCount, duration / 1000000.0);
	}

	for (int i = 0; i < streamCount; i++) {
		const void *chunkBuffer;
		size_t chunkSize;
		media_header mediaHeader;
		for (int j = 0; j < 5; j++) {
			status = reader->GetNextChunk(cookies[i], &chunkBuffer, &chunkSize, &mediaHeader);
			if (status != B_OK) {
				TRACE("main: GetNextChunk(stream = %d, chunk = %d) failed with error 0x%lx (%s)\n",
					i, j, status, strerror(status));
				break;
			}
		}

		int64 frame;
		bigtime_t time;
		
		time = 1000000; // 1 sec
		TRACE("main: calling Seek(stream = %d, time %.6f forward)\n", i, time / 1000000.0);
		status = reader->Seek(cookies[i],
			B_MEDIA_SEEK_TO_TIME | B_MEDIA_SEEK_CLOSEST_FORWARD, &frame, &time);
		TRACE("main: Seek result: time %.6f, frame %Ld\n", time / 1000000.0, frame);

		frame = 1000;
		TRACE("main: calling Seek(stream = %d, frame %Ld forward)\n", i, frame);
		status = reader->Seek(cookies[i],
			B_MEDIA_SEEK_TO_FRAME | B_MEDIA_SEEK_CLOSEST_FORWARD, &frame, &time);
		TRACE("main: Seek result: time %.6f, frame %Ld\n", time / 1000000.0, frame);

		time = 1000000; // 1 sec
		TRACE("main: calling Seek(stream = %d, time %.6f backward)\n", i, time / 1000000.0);
		status = reader->Seek(cookies[i],
			B_MEDIA_SEEK_TO_TIME | B_MEDIA_SEEK_CLOSEST_BACKWARD, &frame, &time);
		TRACE("main: Seek result: time %.6f, frame %Ld\n", time / 1000000.0, frame);

		frame = 1000;
		TRACE("main: calling Seek(stream = %d, frame %Ld backward)\n", i, frame);
		status = reader->Seek(cookies[i],
			B_MEDIA_SEEK_TO_FRAME | B_MEDIA_SEEK_CLOSEST_BACKWARD, &frame, &time);
		TRACE("main: Seek result: time %.6f, frame %Ld\n", time / 1000000.0, frame);
	}

	for (int i = 0; i < streamCount; i++) {
		TRACE("main: calling FreeCookie(stream = %d)\n", i);
		status = reader->FreeCookie(cookies[i]);
		if (status != B_OK) {
			TRACE("main: FreeCookie(stream = %d) failed with error 0x%lx (%s)\n",
				i, status, strerror(status));
			goto err;
		}
	}

err:
	delete reader;
	delete plugin;
	delete source;

	return 0;
}