Exemple #1
0
OP_STATUS
MediaSourceImpl::Init()
{
	m_use_url.SetURL(m_key_url);
	// Purge the resource from cache if it is expired or we are using
	// the streaming cache. Cache invalidation during the lifetime of
	// the MediaSourceImpl instance is not supported, see CORE-27748.
	if (m_use_url->Expired(TRUE) || IsStreaming())
		m_use_url->Unload();
	m_use_url->SetAttribute(URL::KMultimedia, TRUE);
	m_use_url->SetAttribute(URL::KSendAcceptEncoding, FALSE);
	return SetCallBacks();
}
Exemple #2
0
// ==== コンストラクタ
ANAS::Activity::Activity( ANAS::ActivityConfigration &_conf ):
pActivity( _conf.pActivity ), pSavedState( _conf.pSavedState ), SavedStateSize( _conf.SavedStateSize ),
	pCallBacks( _conf.pUserCallbacks ), pInputInterface( _conf.pInput ), pGraphicInterface( _conf.pGraphic )
{
	Log::i("Activity Constructor","Start Construction" );

	// Destroy Sync.
	DestroyFuture = DestroyPromise.get_future();

	
	// Config
	pConfig = AConfiguration_new();
	if(pConfig){
		AConfiguration_fromAssetManager(pConfig, pActivity->assetManager);
	}

	// Test Code.
	
	/*
	const char* asset_name = "android_logo.png";
	AAsset *asset = AAssetManager_open(pActivity->assetManager, asset_name, AASSET_MODE_STREAMING);
	if(asset){
		int Asset_size = AAsset_getLength(asset);
		const void *Asset_ptr = AAsset_getBuffer(asset);


		boost::format asset_format("FILE: %1%, SIZE: %2%");
		Log::e("Asset Test", (asset_format % asset_name % Asset_size).str().c_str() );
		
		
		Image _test_img;
		_test_img.Load<IFT_PNG>( Asset_ptr );

		AAsset_close( asset );
	}
	*/
	


	// CallBacks
	SetCallBacks(pActivity->callbacks);

	Log::i("Activity Constructor", "End Construction");
}
Exemple #3
0
/* virtual */ void
MediaSourceImpl::HandleCallback(OpMessage msg, MH_PARAM_1 par1, MH_PARAM_2 par2)
{
	if (msg == MSG_MEDIA_SOURCE_ENSURE_BUFFERING)
	{
		OP_ASSERT(m_pending_ensure);
		EnsureBuffering();
		m_pending_ensure = FALSE;
		return;
	}
	else if (msg == MSG_MEDIA_SOURCE_NOTIFY_LISTENER)
	{
		// The listener may have been removed while the message was
		// pending, so find it in the listeners list before notifying.
		MediaProgressListener* listener = reinterpret_cast<MediaProgressListener*>(par2);
		for (OpListenersIterator iter(m_listeners); m_listeners.HasNext(iter);)
		{
			if (m_listeners.GetNext(iter) == listener)
			{
				if (m_state == FAILED)
					listener->OnError(this);
				else if (m_state == IDLE)
					listener->OnIdle(this);
				// else: The state has already changed and the
				// listener was notified just like the others.
				break;
			}
		}
		return;
	}

	// URL_DataDescriptor::RetrieveData posts MSG_URL_DATA_LOADED when
	// reading, which we are not interested in when idle or paused.
	// URL messages after an error are irrelevant to us.
	if (m_state == IDLE || m_state == PAUSED || m_state == FAILED)
		return;

	// URL messages in the message queue when calling StopLoading
	// will arrive after starting a new request, at which point they
	// must be ignored. Wait for headers/failure/redirect.
	if (m_state == STARTED && msg == MSG_URL_DATA_LOADED)
		return;

	OP_ASSERT(m_state == STARTED || m_state == HEADERS || m_state == LOADING);
	switch(msg)
	{
	case MSG_HEADER_LOADED:
		OP_ASSERT(m_state == STARTED);
		m_state = HEADERS;
		// If we are streaming, tell all listeners except the first to
		// restart loading, at which point they'll get a new source.
		if (IsStreaming())
		{
			OpListenersIterator iter(m_listeners);
			m_listeners.GetNext(iter);
			while (m_listeners.HasNext(iter))
				m_listeners.GetNext(iter)->OnClientCollision(this);
		}
		break;
	case MSG_URL_DATA_LOADED:
		if (m_state == HEADERS)
			m_state = LOADING;
		OP_ASSERT(m_state == LOADING);
		if (IsSuccessURL(m_use_url))
		{
			// This point will be reached very often while the
			// transfer is progressing normally, so it is important
			// that the following steps are not needlessly wasteful.

			if (!VerifyContentType())
				return;

			// EnsureBuffering does a non-trivial amount of work, so
			// only call it if (a) the request has finished or (b) the
			// current request is "too big" and needs clamping.
			if (m_clamp_request || IsLoadedURL(m_use_url))
			{
				EnsureBuffering();
				if (m_state != LOADING)
					break;
			}

			// The listeners are responsible for throttling the
			// side-effects buffering progress.
			for (OpListenersIterator iter(m_listeners); m_listeners.HasNext(iter);)
				m_listeners.GetNext(iter)->OnProgress(this);

			if (IsStreaming())
			{
				BOOL available;
				OpFileLength remaining;
				GetStreamingCoverage(available, remaining);
				if (available && remaining < STREAMING_CACHE_PAUSE_LIMIT)
					PauseBuffering();
			}
		}
		else
		{
			LoadFailed();
		}
		break;
	case MSG_URL_LOADING_FAILED:
		// Try to recover from a network errors that happen while
		// loading, but not those that happen before (or after) that.
		if (m_state == LOADING && IsResumableURL(m_use_url))
		{
			StopBuffering();
			m_state = IDLE;
			EnsureBuffering();
		}
		else
		{
			LoadFailed();
		}
		break;
	case MSG_URL_MOVED:
		{
			URL moved_to = m_use_url->GetAttribute(URL::KMovedToURL, URL::KFollowRedirect);
			if (!moved_to.IsEmpty())
			{
				OP_ASSERT(m_use_url->Id(URL::KFollowRedirect) == (URL_ID)par2 &&
						  moved_to.Id(URL::KNoRedirect) == (URL_ID)par2);
				m_use_url.SetURL(moved_to);
				OP_DELETE(m_url_dd);
				m_url_dd = NULL;
				m_message_handler->UnsetCallBacks(this);
				RAISE_AND_RETURN_VOID_IF_ERROR(SetCallBacks());
			}
		}
		break;
	default:
		OP_ASSERT(FALSE);
	}

	// Ensure that we are notified of further buffering progress.
	if (m_url_dd)
		m_url_dd->ClearPostedMessage();
}