Exemplo n.º 1
0
void HostCOOMatrix<ValueType>::ReadFile(const std::string filename) 
{
    DEBUGLOG(this, "HostCOOMatrix::ReadFile()", "filename = " << filename, 2);
    BaseMatrix<ValueType>::ReadFile(filename);

    //Allocate matrix after reading the size from the file
    this->Allocate(this->mNRows, this->mNCols, this->mNnz);
    // Re open file
    std::ifstream mFile;
    mFile.exceptions ( std::ifstream::failbit | std::ifstream::badbit );
    mFile.open(filename);
    // Go to line 3 where the data begins

    GoToLine(mFile, 3);
    std::string line;
    std::getline(mFile, line);
    // Only check syntax on first line for performance issues
    // Checking regex in each iteration very slow
    if (!regex_match (line, std::regex("^((?:(?:[0-9][0-9]*\\s+?){2})"
                                "-?[0-9\\.]+e(?:\\+|\\-)[0-9]+)")))
    {
        std::cerr << "Bad syntax in line: 3" << std::endl;
    }
    GoToLine(mFile, 3);
    std::istringstream linestream;
    for (int index=0; index<this->mNnz; index++)
    {
        std::getline(mFile, line);
        linestream.str(line); 
        int rowInd, colInd;
        linestream >> rowInd >> colInd >> mData[index];
        mRowInd[index] = rowInd - 1;
        mColInd[index] = colInd - 1;
        linestream.clear();
        
    }
    mFile.close();
    DEBUGEND();

}
Exemplo n.º 2
0
VOID FspFileNodeSetFileInfo(FSP_FILE_NODE *FileNode, PFILE_OBJECT CcFileObject,
    const FSP_FSCTL_FILE_INFO *FileInfo)
{
    PAGED_CODE();

    FSP_FSVOL_DEVICE_EXTENSION *FsvolDeviceExtension =
        FspFsvolDeviceExtension(FileNode->FsvolDeviceObject);
    UINT64 AllocationSize = FileInfo->AllocationSize > FileInfo->FileSize ?
        FileInfo->AllocationSize : FileInfo->FileSize;
    UINT64 AllocationUnit;

    AllocationUnit = FsvolDeviceExtension->VolumeParams.SectorSize *
        FsvolDeviceExtension->VolumeParams.SectorsPerAllocationUnit;
    AllocationSize = (AllocationSize + AllocationUnit - 1) / AllocationUnit * AllocationUnit;

    FileNode->Header.AllocationSize.QuadPart = AllocationSize;
    FileNode->Header.FileSize.QuadPart = FileInfo->FileSize;

    FileNode->FileAttributes = FileInfo->FileAttributes;
    FileNode->ReparseTag = FileInfo->ReparseTag;
    FileNode->CreationTime = FileInfo->CreationTime;
    FileNode->LastAccessTime = FileInfo->LastAccessTime;
    FileNode->LastWriteTime = FileInfo->LastWriteTime;
    FileNode->ChangeTime = FileInfo->ChangeTime;
    FileNode->InfoExpirationTime = FspExpirationTimeFromMillis(
        FsvolDeviceExtension->VolumeParams.FileInfoTimeout);
    FileNode->InfoChangeNumber++;

    if (0 != CcFileObject)
    {
        NTSTATUS Result = FspCcSetFileSizes(
            CcFileObject, (PCC_FILE_SIZES)&FileNode->Header.AllocationSize);
        if (!NT_SUCCESS(Result))
        {
            DEBUGLOG("FspCcSetFileSizes error: %s", NtStatusSym(Result));
            DEBUGBREAK_CRIT();
            CcUninitializeCacheMap(CcFileObject, 0, 0);
        }
    }
}
Exemplo n.º 3
0
wxSize MutIconShapeClass<T>::DoGetBestSize() const 
{
	//  wxSize s(GetWindowBorderSize()/2);
	wxSize s(0,0);
	wxSize s1(0,0);
	DEBUGLOG (other, _T("best size: %dx%d"),s.x,s.y);
//	return s;
	
	
	if (staticText) s += staticText->GetBestSize();
	DEBUGLOG (other, _T("staticText %p best size: %dx%d"),(void*)&staticText,s.x,s.y);
	if (GetIcon().IsOk()) {
		s.x = std::max (Icon.GetWidth(), s.x);
		int h = Icon.GetHeight();
		s.y += h;
	}

	if (this->GetSizer()) {
		s1 = this->GetSizer()->CalcMin();
		DEBUGLOG (other, _T("our %p sizer best size: %dx%d"),(void*)this,s1.x,s1.y);
		s.x = std::max(s.x,s1.x);
		s.y += std::max(s1.y,0);
	}

#ifdef DEBUG
	wxSize s2 = this->GetSize() - this->GetClientSize();
	s2.IncTo(wxSize(0,0));

	DEBUGLOG(gui,_T("s1: (%d,%d), maxBorderSize: (%d,%d)"),
		 s2.x,s2.y,2*maxBorderSize.x,2*maxBorderSize.y);
	mutASSERT(!maxBorderSize.x || s2.x <= 2*maxBorderSize.x);
	mutASSERT(!maxBorderSize.y || s2.y <= 2*maxBorderSize.y);
#endif

	s += maxBorderSize + maxBorderSize;
	
	// s1 = MutPanel::DoGetBestSize();
        // call to base class not needed.
	DEBUGLOG (other, _T("our %p parent best size: %dx%d"),(void*)this,s1.x,s1.y);
	
	s1.IncTo(s);

	DEBUGLOG (other, _T("our %p best size: %dx%d"),(void*)this,s.x,s.y);
	wxConstCast(this,MutIconShapeClass<T>)->SetMinSize(s1);
	this->CacheBestSize(s1);
	return s1;
}
Exemplo n.º 4
0
void SCDEVICE::LateInit(void)
{
  DEBUGLOG("%s", __FUNCTION__);
  int n = CardIndex();
  if (DeviceNumber() != n)
    ERRORLOG("CardIndex - DeviceNumber mismatch! Put DVBAPI plugin first on VDR commandline!");
  softcsa = (fd_ca < 0);
  if (softcsa)
  {
    if (HasDecoder())
      INFOLOG("Card %s is a full-featured card but no ca device found!", devId);
  }
  else if (cScDevices::ForceBudget(n))
  {
    INFOLOG("Budget mode forced on card %s", devId);
    softcsa = true;
  }
  if (softcsa)
  {
    INFOLOG("Using software decryption on card %s", devId);
  }
}
Exemplo n.º 5
0
static void add_env_variable( lua_State* L,  const char* key, const char* env ) 
{
    char* envdata;
    
    DEBUGLOG( "Registering env variable: %s", env );

    // Put the key onto the stack
    lua_pushstring( L, key );

    // Put the environment data onto the stack
    envdata = getenv( env );
    if ( envdata == NULL ) 
    {
        lua_pushstring( L, "" );
    }
    else 
    {
        lua_pushstring( L, envdata );
    }

    lua_settable( L, -3 );
}
Exemplo n.º 6
0
Vector<ValueType> Vector<ValueType>::operator+(
                                const Vector<ValueType>& otherVector)
{
    DEBUGLOG( this, "Vector::operator+", "Vec =" << &otherVector, 1);
    assert(GetSize() == otherVector.GetSize());
    assert(( IsHost() && otherVector.IsHost() )|| 
            (IsDevice() && otherVector.IsDevice()) );

    Vector<ValueType> result(GetSize());

    if (pImpl == pImplHost)
        result.pImpl->Add(*(otherVector.pImpl), *pImpl);
    else if (pImpl == pImplDevice)
    {
        result.MoveToDevice();
        result.pImpl->Add(*(otherVector.pImpl), *pImpl);
    }

    DEBUGEND();
    return result;
        
}
Exemplo n.º 7
0
App::~App()
{
  DEBUGLOG("~App;");
  delete debugger;

  delete player;

  delete app_settings;
  delete midi;
  delete audio;

  delete file_system;

  if (screen)
    SDL_FreeSurface(screen);
  if (sdlTexture)
    SDL_DestroyTexture(sdlTexture);
  if (sdlRenderer)
    SDL_DestroyRenderer(sdlRenderer);
  if(sdlWindow)
    SDL_DestroyWindow(sdlWindow);
}
/* Called by init_cluster() to open up the listening socket */
int init_comms(unsigned short port)
{
    struct sockaddr_in6 addr;

    sock_hash = dm_hash_create(100);
    tcp_port = port ? : DEFAULT_TCP_PORT;

    listen_fd = socket(AF_INET6, SOCK_STREAM, 0);

    if (listen_fd < 0)
    {
	return -1;
    }
    else
    {
	int one = 1;
	setsockopt(listen_fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(int));
	setsockopt(listen_fd, SOL_SOCKET, SO_KEEPALIVE, &one, sizeof(int));
    }

    memset(&addr, 0, sizeof(addr)); // Bind to INADDR_ANY
    addr.sin6_family = AF_INET6;
    addr.sin6_port = htons(tcp_port);

    if (bind(listen_fd, (struct sockaddr *)&addr, sizeof(addr)) < 0)
    {
	DEBUGLOG("Can't bind to port: %s\n", strerror(errno));
	syslog(LOG_ERR, "Can't bind to port %d, is clvmd already running ?", tcp_port);
	close(listen_fd);
	return -1;
    }

    listen(listen_fd, 5);

    /* Set Close-on-exec */
    fcntl(listen_fd, F_SETFD, 1);

    return 0;
}
Exemplo n.º 9
0
/* Call a callback for each node, so the caller knows whether it's up or down */
static int _cluster_do_node_callback(struct local_client *master_client,
				     void (*callback)(struct local_client *,
						      const char *csid, int node_up))
{
	struct dm_hash_node *hn;
	struct node_info *ninfo;
	int somedown = 0;

	dm_hash_iterate(hn, node_hash)
	{
		char csid[COROSYNC_CSID_LEN];

		ninfo = dm_hash_get_data(node_hash, hn);
		memcpy(csid, dm_hash_get_key(node_hash, hn), COROSYNC_CSID_LEN);

		DEBUGLOG("down_callback. node %d, state = %d\n", ninfo->nodeid,
			 ninfo->state);

		if (ninfo->state != NODE_DOWN)
			callback(master_client, csid, ninfo->state == NODE_CLVMD);
		if (ninfo->state != NODE_CLVMD)
			somedown = -1;
	}
Exemplo n.º 10
0
SCCIAdapter::~SCCIAdapter()
{
  DEBUGLOG("%s", __FUNCTION__);

  Cancel(3);

  for (int i = 0; i < MAX_SOCKETS; i++)
  {
    if (sockets[i] > 0)
      close(sockets[i]);
    sockets[i] = 0;
  }
  ciMutex.Lock();
  delete rb;
  rb = 0;
  ciMutex.Unlock();

  if (decsa)
    delete decsa;
  if (capmt != 0)
    delete capmt;
  capmt = 0;
}
Exemplo n.º 11
0
bool cLiveQueue::Add(MsgPacket* p)
{
  cMutexLock lock(&m_lock);

  // in timeshift mode ?
  if(m_pause || (!m_pause && m_writefd != -1))
  {
    // write packet
    if(!p->write(m_writefd, 1000))
    {
      DEBUGLOG("Unable to write packet into timeshift ringbuffer !");
      return false;
    }

    // ring-buffer overrun ?
    off_t length = lseek(m_writefd, 0, SEEK_CUR);
    if(length >= (off_t)BufferSize)
    {
      // truncate to current position
      if(ftruncate(m_writefd, length) == 0)
        lseek(m_writefd, 0, SEEK_SET);
    }
    return true;
  }

  // queue too long ?
  if (size() > 100) {
    delete p;
    return false;
  }

  // add packet to queue
  push(p);
  m_cond.Signal();

  return true;
}
Exemplo n.º 12
0
void SCCIAdapter::OSCamCheck()
{
  for (int i = 0; i < MAX_SOCKETS; i++)
  {
    if (sockets[i] != 0)
    {
      DEBUGLOG("%s: %d: checking if connection to socket_fd=%d is still alive", __FUNCTION__, cardIndex, sockets[i]);
      if ((sockets[i] == -1) || (write(sockets[i], NULL, 0) < 0))
      {
        if (sids[i] != 0)    //we have a SID assigned with this socket, need to reconnect and resend PMT data
        {
          int new_fd = capmt->send(cardIndex, sids[i], -1, NULL, 0);
          if (new_fd > 0)
          {
            INFOLOG("%d: reconnected successfully, replacing socket_fd %d with %d", cardIndex, sockets[i], new_fd);
            sockets[i] = new_fd;
          }
        }
        else                 //no SID assigned to this socket, mark as invalid
          sockets[i] = 0;
      }
    }
  }
}
Exemplo n.º 13
0
	void OpenGLGraphicSystem::ProcessShader( BohgeEngine::ShaderProperty::ShaderCode sc, eastl::string& code )
	{
		Utility::RemoveTargetString( code, "precision highp float;" );
		Utility::RemoveTargetString( code, "precision mediump float;" );
		Utility::RemoveTargetString( code, "precision lowp float;" );
		Utility::RemoveTargetString( code, "highp " );
		Utility::RemoveTargetString( code, "mediump " );
		Utility::RemoveTargetString( code, "lowp " );
		code.insert(0, "#define	MAXJOINTS	128\n" );
		code.insert(0, "#define	MAXARRAYSIZE	256\n" );
		code.insert(0, "#define	_WINDOWS_\n" );
		glslopt_shader_type type;
		switch( sc )
		{
		case ShaderProperty::SC_VERTEX: type = kGlslOptShaderVertex; break;
		case ShaderProperty::SC_FRAGMENT: type = kGlslOptShaderFragment; break;
		default:ASSERT(false);
		}

		glslopt_shader* shader = glslopt_optimize( m_pGlslopt_ctx, type, code.c_str(), 0 );
		if ( glslopt_get_status(shader) )
		{
			code = glslopt_get_output( shader );
		}
		else
		{
			const char* log = glslopt_get_log( shader );
			DEBUGLOG("Can't optimize shader, caz %s\n", log );
		}
		if ( ShaderProperty::SC_VERTEX == sc )
		{
			size_t mainbegin = _FindMainFunction(code);
			_FixAttributeIndexingType( code, mainbegin );
		}
		glslopt_shader_delete( shader );
	}
Exemplo n.º 14
0
bool cLiveStreamer::IsReady()
{
  if(m_ready)
    return true;

  bool bAllParsed = true;

  for (std::list<cTSDemuxer*>::iterator i = m_Demuxers.begin(); i != m_Demuxers.end(); i++)
  {
    /*if((*i)->IsParsed() && (*i)->GetContent() == cStreamInfo::scVIDEO) {
      bAllParsed = true;
      break;
    }*/
    if (!(*i)->IsParsed()) {
      DEBUGLOG("Stream with PID %i not parsed", (*i)->GetPID());
      bAllParsed = false;
      break;
    }
  }

  m_ready = bAllParsed;

  return bAllParsed;
}
Exemplo n.º 15
0
cLiveStreamer::~cLiveStreamer()
{
  DEBUGLOG("Started to delete live streamer");

  cTimeMs t;

  DEBUGLOG("Stopping streamer thread ...");
  Cancel(5);
  DEBUGLOG("Done.");

  cMutexLock lock(&m_FilterMutex);

  DEBUGLOG("Detaching");

  if(m_PatFilter != NULL && m_Device != NULL) {
    m_Device->Detach(m_PatFilter);
    delete m_PatFilter;
    m_PatFilter = NULL;
  }

  if (IsAttached()) {
    Detach();
  }

  for (std::list<cTSDemuxer*>::iterator i = m_Demuxers.begin(); i != m_Demuxers.end(); i++) {
    if ((*i) != NULL) {
      DEBUGLOG("Deleting stream demuxer for pid=%i and type=%i", (*i)->GetPID(), (*i)->GetType());
      delete (*i);
    }
  }
  m_Demuxers.clear();

  delete m_Queue;

  m_uid = 0;

  {
    cMutexLock lock(&m_DeviceMutex);
    m_Device = NULL;
  }

  DEBUGLOG("Finished to delete live streamer (took %llu ms)", t.Elapsed());
}
Exemplo n.º 16
0
static int _init_cluster(void)
{
	cs_error_t err;

#ifdef QUORUM_SET	/* corosync/quorum.h */
	uint32_t quorum_type;
#endif

	node_hash = dm_hash_create(100);

	err = cpg_initialize(&cpg_handle,
			     &corosync_cpg_callbacks);
	if (err != CS_OK) {
		syslog(LOG_ERR, "Cannot initialise Corosync CPG service: %d",
		       err);
		DEBUGLOG("Cannot initialise Corosync CPG service: %d", err);
		return cs_to_errno(err);
	}

#ifdef QUORUM_SET
	err = quorum_initialize(&quorum_handle,
				&quorum_callbacks,
				&quorum_type);

	if (quorum_type != QUORUM_SET) {
		syslog(LOG_ERR, "Corosync quorum service is not configured");
		DEBUGLOG("Corosync quorum service is not configured");
		return EINVAL;
	}
#else
	err = quorum_initialize(&quorum_handle,
				&quorum_callbacks);
#endif

	if (err != CS_OK) {
		syslog(LOG_ERR, "Cannot initialise Corosync quorum service: %d",
		       err);
		DEBUGLOG("Cannot initialise Corosync quorum service: %d", err);
		return cs_to_errno(err);
	}

	/* Create a lockspace for LV & VG locks to live in */
	lockspace = dlm_open_lockspace(LOCKSPACE_NAME);
	if (!lockspace) {
		lockspace = dlm_create_lockspace(LOCKSPACE_NAME, 0600);
		if (!lockspace) {
			syslog(LOG_ERR, "Unable to create DLM lockspace for CLVM: %m");
			return -1;
		}
		DEBUGLOG("Created DLM lockspace for CLVMD.\n");
	} else
		DEBUGLOG("Opened existing DLM lockspace for CLVMD.\n");

	dlm_ls_pthread_init(lockspace);
	DEBUGLOG("DLM initialisation complete\n");

	/* Connect to the clvmd group */
	strcpy((char *)cpg_group_name.value, "clvmd");
	cpg_group_name.length = strlen((char *)cpg_group_name.value);
	err = cpg_join(cpg_handle, &cpg_group_name);
	if (err != CS_OK) {
		cpg_finalize(cpg_handle);
		quorum_finalize(quorum_handle);
		dlm_release_lockspace(LOCKSPACE_NAME, lockspace, 1);
		syslog(LOG_ERR, "Cannot join clvmd process group");
		DEBUGLOG("Cannot join clvmd process group: %d\n", err);
		return cs_to_errno(err);
	}

	err = cpg_local_get(cpg_handle,
			    &our_nodeid);
	if (err != CS_OK) {
		cpg_finalize(cpg_handle);
		quorum_finalize(quorum_handle);
		dlm_release_lockspace(LOCKSPACE_NAME, lockspace, 1);
		syslog(LOG_ERR, "Cannot get local node id\n");
		return cs_to_errno(err);
	}
	DEBUGLOG("Our local node id is %d\n", our_nodeid);

	DEBUGLOG("Connected to Corosync\n");

	return 0;
}
Exemplo n.º 17
0
	//-------------------------------------------------------------------
	void StateManager::SwitchState(Engine& engine)
	{
		engine.GetActionManager()->SetResponse(false);//状态切换停止保存案件buffer
		DEBUGLOG("State Change to %d!\n", static_cast<int>(m_eNextState));
		if( ! m_lStateList.empty() )
		{
			m_lStateList.begin()->m_pStatePtr->OnLeave(engine);//通知久的状态机需要推出了
			m_ePreviousState = m_lStateList.begin()->m_eStateName;
		}
		//新建新状态
		bool isExist = false;
		StateList::iterator it;
		if( !m_lStateList.empty() )
		{
			if ( m_eNextState != m_lStateList.begin()->m_eStateName )//切换自身被认为是重置
			{
				for(it = ++(m_lStateList.begin());
					it != m_lStateList.end();
					it++)
				{
					if( it->m_eStateName == m_eNextState )
					{
						isExist = true;
						break;
					}
				}
			}
		}
		//如果更换状态,删除旧的状态
		if( true == m_isReplace )
		{
			if( ! m_lStateList.empty() )
			{
				for ( StateList::iterator it = m_lStateList.begin();
					it != m_lStateList.end() ;
				 )
				{
					if( m_ClearOtherState )
					{
						if ( m_eNextState != it->m_eStateName )
						{
							it->m_pStatePtr->ReleaseResource(engine);
							SAFE_DELETE( it->m_pStatePtr );
							it = m_lStateList.erase( it );
						}
						else
						{
							it ++;
						}
					}
					else
					{
						if( m_ePreviousState == it->m_eStateName )//删除需要替换掉的状态机
						{
							it->m_pStatePtr->ReleaseResource(engine);
							SAFE_DELETE( it->m_pStatePtr );
							it = m_lStateList.erase( it );
							break;
						}
						it ++;
					}
				}
			}
		}
		//设置新的
		IGameState* state;
		if( isExist )
		{
			m_isLoadResouce = false; //状态如果在堆栈中这里不需要再次读取,所以为false
			state = it->m_pStatePtr;
			state->OnEnter(engine, m_ePreviousState );

			//一下执行从新放到栈首的操作
			StateInfo newInfo(state, it->m_eStateName );
			m_lStateList.erase(it);
			m_lStateList.push_front(newInfo);
		}
		else
		{
			switch(m_eNextState)
			{
			case State_None:
				{
					ASSERT(false);
				}break;
			case State_Logo:
				{
					state = NEW StateLogo();
				}break;
			case State_Main_Menu:
				{
					state = NEW StateMainMenu();
				}break;
			}
			StateInfo newInfo(state, m_eNextState);
			//新状态压住栈首
			//newState->LoadResource(engine);
			if( m_isShowLoading )
			{
				m_pLoading->SetShow(true);
				m_pLoading->TopMost();
				m_isLoadResouce = true;
			}
			else
			{
				m_isJustSwitch = true;
				state->LoadResource(engine);
				state->OnEnter(engine, m_ePreviousState );
			}
			m_lStateList.push_front(newInfo);
		}

		m_isSwitchState = false;
		m_isReplace = false;
		m_ClearOtherState = false;
		m_eNextState = State_None;
		engine.GetActionManager()->SetResponse(true);//回复
	}
Exemplo n.º 18
0
static void printGLString(const char *name, GLenum s)
{
    const char *v = (const char *)glGetString( s );
    DEBUGLOG( "GL %s = %s\n", name, v );
}
SoundLibrarySaveDialog::~SoundLibrarySaveDialog()
{
	DEBUGLOG( "DESTROY" );

}
Exemplo n.º 20
0
void cVnsiOsd::Cmd(int cmd, int wnd, int color, int x0, int y0, int x1, int y1, const void *data, int size)
{
  DEBUGLOG("OSD: cmd: %d, wnd: %d, color: %d, x0: %d, y0: %d, x1: %d, y1: %d",
      cmd, wnd, color, x0, y0, x1, y1);
  cVnsiOsdProvider::SendOsdPacket(cmd, wnd, color, x0, y0, x1, y1, data, size);
}
Exemplo n.º 21
0
static void handle_fragment(server *srv, connection *con, void *plugindata)
{
	int err;
	plugin_data *p = plugindata;
	off_t range_start, range_end;
	
	if (copy_bits_session_id_or_set_error(srv, con))
		return;

	err = get_range(srv, con, con->range_offset, &range_start, &range_end);

	if (range_start > p->state.abs_off || range_end < p->state.abs_off) {
		//BITS requests must be contiguious - a Transient error may have occured
		DEBUGLOG("sooo", "The fragment range is greater than abs_off", range_start, p->state.abs_off, range_end);
		con->http_status = 416;
		err = -EINVAL;
		goto done;
	}

	if (((con->range_offset + range_start) < p->state.abs_off) && (range_end > p->state.abs_off)){
		DEBUGLOG("sooo", "Fragment Overlaps Abs_off:", con->range_offset + range_start, p->state.abs_off, range_end);
		//Discard bytes we already have:
		//discard_bytes(srv, con->request_content_queue, p->state.abs_off - (con->range_offset + range_start)+1);

		//DEBUGLOG("sos", "Discarded", p->state.abs_off -(range_start + con->range_offset), "bytes");
		//con->range_offset = p->state.abs_off - range_start;
		//DEBUGLOG("so", "Setting range offset - ", con->range_offset);
		p->state.abs_off = con->range_offset + range_start;
		DEBUGLOG("so", "Re-adjust abs_off", p->state.abs_off);
	}
	
	/* *PREVIOUS IMPLEMENTATION OF 416 - Discards already written data*
	if ( range_end < p->state.abs_off ) {
		DEBUGLOG("soo", "The requests range has already been dealt with", range_start, range_end);
		//Set the range_offset to be the content_length, to return with a healthy 200 http_status
		con->range_offset = con->request.content_length;
		goto done;
		}*/

	DEBUGLOG("so", "Range Offset", con->range_offset);
	DEBUGLOG("soo","Handling Fragment (start/end)", range_start, range_end);
	if (err)
		goto done;

	while (1) {
		if (chunkqueue_avail(con->request_content_queue) >
		    range_end - range_start + 1 - con->range_offset) {
			LOG("sdo", "More data than we want!",
			    chunkqueue_avail(con->request_content_queue),
			    range_end - range_start + 1 - con->range_offset);
			err = -EINVAL;
			goto done;
		}

		err = process_data(srv, con, p, con->physical.path,
				   con->request_content_queue, range_start);
		if (err)
			goto done;

		if (con->range_offset >= range_end - range_start + 1 || 
		     chunkqueue_avail(con->request_content_queue) == 0){
			DEBUGLOG("sd", "Leaving for more data", chunkqueue_avail(con->request_content_queue));
			break;
		}
	}

done:
	/*
	if (con->range_offset == range_end - range_start + 1) {
		buffer_reset(p->tmpbuf);
		if (err)
			buffer_append_off_t(p->tmpbuf, range_start);
		else
			buffer_append_off_t(p->tmpbuf, range_end + 1);

		DEBUGLOG("sdb", "BITS-Received-Content-Range header length",
				p->tmpbuf->used, p->tmpbuf);
		response_header_insert(srv, con,
				CONST_STR_LEN("BITS-Received-Content-Range"),
				CONST_BUF_LEN(p->tmpbuf));
	} 

	*/
	DEBUGLOG("so", "Abs_off", p->state.abs_off);

	if (!err) {
		DEBUGLOG("s", "Resetting HTTP Status");
		con->http_status = 0;
		return;
	}

	if (con->http_status != 416 && con->http_status != 400)
		con->http_status = 400;

       
	if (con->http_status = 416) {
		buffer_reset(p->tmpbuf);
		buffer_append_off_t(p->tmpbuf, p->state.abs_off);
		response_header_insert(srv, con,
				       CONST_STR_LEN("BITS-Received-Content-Range"),
						     CONST_BUF_LEN(p->tmpbuf));
	
	 }

	set_error(srv, con, con->http_status, BITS_E_INVALIDARG);
}
Exemplo n.º 22
0
static int process_data(server *srv, connection *con, plugin_data *p,
			buffer *filename, chunkqueue *cq, off_t range_start)
{
	int err;
	size_t len;
	//off_t *abs_off;
	vhd_state_t *state;
	vhd_context_t *vhd;

	err = 0;
	state = &p->state;
	vhd = &state->vhd;
	//abs_off = range_start + con->range_offset;
	//abs_off = state->abs_off;
	DEBUGLOG("so", "Absolute Offset", state->abs_off);
	DEBUGLOG("sd", "Current Virtual Block = ", state->curr_virt_blk);
	if (state->curr_virt_blk != -1) {
		DEBUGLOG("s", "Process Block");
		err = process_block(srv, cq, state, &(state->abs_off));
		goto done;
	}

	if (state->abs_off < 0 + sizeof(vhd_footer_t)) {
		err = get_footer(srv, cq, state, &(state->abs_off));
		goto done;
	}

	if (((off_t)state->abs_off) < vhd->footer.data_offset + sizeof(vhd_header_t)) {
		err = get_header(srv, cq, state, &(state->abs_off));
		goto done;
	}

	if (((off_t)state->abs_off) < vhd->header.table_offset + state->bat_buf_size) {
		err = get_bat(srv, cq, state, &(state->abs_off));
		if (err)
			goto done;
		if (state->vhd_ready)
			err = prepare_for_write(srv, state, filename, state->abs_off);
		goto done;
	}

	if (state->blocks_written < state->blocks_allocated) {
		LOG("sdd", "BUG!", state->blocks_written,
				state->blocks_allocated);
		err = -EINVAL;
		goto done;
	}

	// TODO: we could actually validate the primary footer at the end
	len = chunkqueue_avail(cq);
	DEBUGLOG("sd", "Discarding the remainder", len);
	discard_bytes(srv, cq, len);
	state->abs_off += len;

	if (state->zero_unalloc) {
		err = zero_unallocated(srv, state);
		state->zero_unalloc = 0;
	}

done:
	con->range_offset = state->abs_off - range_start;
	return err;
}
Exemplo n.º 23
0
MRESULT IntrospectBase::DlgProc(ULONG msg, MPARAM mp1, MPARAM mp2)
{
  switch (msg)
  {case WM_INITDLG:
    { MRESULT ret = DialogBase::DlgProc(msg, mp1, mp2);
      do_warpsans(GetHwnd());
      // Populate MRU list
      ComboBox cb(GetCtrl(CB_SERVER));
      if (Configuration.SinkServer)
        cb.InsertItem(Configuration.SinkServer);
      char key[] = "Server1";
      do
      { xstring url;
        ini_query(key, url);
        if (!url)
          break;
        cb.InsertItem(url);
      } while (++key[sizeof key -2] <= '9');
      return ret;
    }

   case WM_COMMAND:
    DEBUGLOG(("IntrospectBase::DlgProc:WM_COMMAND(%i,%i, %p)\n", SHORT1FROMMP(mp1), SHORT2FROMMP(mp1), mp2));
    switch (SHORT1FROMMP(mp1))
    {case PB_UPDATE:
      PostMsg(UM_CONNECT, 0,0);
      return 0;
     case DID_OK:
      { ComboBox cb(GetCtrl(CB_SERVER));
        const xstring& server = cb.Text();
        // update MRU list
        if (server.length())
        { char key[] = "Server1";
          int i = 0;
          int len = 0;
          xstring url;
          do
          { if (len >= 0)
            {skip:
              url.reset();
              len = (SHORT)SHORT1FROMMR(WinSendMsg(cb.Hwnd, LM_QUERYITEMTEXTLENGTH, MPFROMSHORT(i), 0));
              if (len >= 0)
              { WinSendMsg(cb.Hwnd, LM_QUERYITEMTEXT, MPFROM2SHORT(i, len+1), MPFROMP(url.allocate(len)));
                DEBUGLOG(("IntrospectBase::DlgProc: save MRU %i: (%i) %s\n", i, len, url.cdata()));
                ++i;
                if (url == server)
                  goto skip;
              }
            }
            ini_write(key, url);
          } while (++key[sizeof key -2] <= '9');
        }
        Configuration.Save();
      }
      break;
    }
    break;

   case WM_CONTROL:
    switch (SHORT1FROMMP(mp1))
    {case CB_SERVER:
      switch (SHORT2FROMMP(mp1))
      {case CBN_ENTER:
        PostMsg(UM_CONNECT, 0,0);
        break;
      }
      break;
     case CB_SINKSRC:
      switch (SHORT2FROMMP(mp1))
      {case CBN_ENTER:
        PostMsg(UM_UPDATE_PORT, 0,0);
        break;
      }
    }
    break;

   case UM_CONNECT:
    { DEBUGLOG(("IntrospectBase::DlgProc:UM_CONNECT\n"));
      // destroy any old connection
      Cleanup();
      const xstring& server = WinQueryDlgItemXText(GetHwnd(), CB_SERVER);
      if (!server.length())
      { WinSetDlgItemText(GetHwnd(), ST_STATUS, "enter server name above");
        return 0;
      }
      // open new connection
      try
      { Context.Connect("PM123", server);
      } catch (const PAException& ex)
      { WinSetDlgItemText(GetHwnd(), ST_STATUS, ex.GetMessage());
      }
      return 0;
    }

   case UM_STATE_CHANGE:
    { pa_context_state_t state = (pa_context_state_t)LONGFROMMP(mp1);
      DEBUGLOG(("IntrospectBase::DlgProc:UM_STATE_CHANGE %u\n", state));
      const char* text = "";
      switch (state)
      {case PA_CONTEXT_CONNECTING:
        text = "Connecting ...";
        break;
       case PA_CONTEXT_AUTHORIZING:
        text = "Authorizing ...";
        break;
       case PA_CONTEXT_SETTING_NAME:
        text = "Set name ...";
        break;
       case PA_CONTEXT_READY:
        text = "Connected";
        PostMsg(UM_DISCOVER_SERVER, 0,0);
        break;
       case PA_CONTEXT_FAILED:
        WinSetDlgItemText(GetHwnd(), ST_STATUS, PAConnectException(Context.GetContext()).GetMessage());
        return 0;
       case PA_CONTEXT_TERMINATED:
        text = "Closed";
        break;
       case PA_CONTEXT_UNCONNECTED:;
      }
      WinSetDlgItemText(GetHwnd(), ST_STATUS, text);
      return 0;
    }
  }
  return DialogBase::DlgProc(msg, mp1, mp2);
}
Exemplo n.º 24
0
void IntrospectBase::StateChangeHandler(const pa_context_state_t& args)
{ DEBUGLOG(("IntrospectBase(%p)::StateChangeHandler(%i)\n", this, args));
  PostMsg(UM_STATE_CHANGE, MPFROMLONG(args), 0);
}
Exemplo n.º 25
0
MRESULT LoadWizard::DlgProc(ULONG msg, MPARAM mp1, MPARAM mp2)
{
  switch (msg)
  {case WM_INITDLG:
    { MRESULT ret = IntrospectBase::DlgProc(msg, mp1, mp2);
      SetTitle(Title);
      if (Configuration.SourceServer)
      { ComboBox(+GetCtrl(CB_SERVER)).Text(Configuration.SourceServer);
        PostMsg(UM_CONNECT, 0, 0);
      }
      if (Configuration.Source)
        PMRASSERT(WinSetDlgItemText(GetHwnd(), CB_SINKSRC, Configuration.Source));
      if (Configuration.SourcePort)
        PMRASSERT(WinSetDlgItemText(GetHwnd(), CB_PORT, Configuration.SourcePort));
      // Init rate spin button
      { SpinButton sb(GetCtrl(SB_RATE));
        sb.SetArray(SamplingRates, sizeof SamplingRates/sizeof *SamplingRates);
        size_t pos;
        if ( !binary_search<const char,const int>(Configuration.SourceRate, pos, &SamplingRates[0], sizeof SamplingRates/sizeof *SamplingRates, &SamplingRateCmp)
          && ( pos == sizeof SamplingRates/sizeof *SamplingRates
            || (pos && 2*Configuration.SourceRate < atoi(SamplingRates[pos]) + atoi(SamplingRates[pos-1])) ))
          --pos;
        sb.Value(pos);
      }
      WinCheckButton(GetHwnd(), Configuration.SourceChannels == 1 ? RB_MONO : RB_STEREO, TRUE);
      return ret;
    }

   case WM_COMMAND:
    DEBUGLOG(("LoadWizard::DlgProc:WM_COMMAND(%i,%i, %p)\n", SHORT1FROMMP(mp1), SHORT2FROMMP(mp1), mp2));
    switch (SHORT1FROMMP(mp1))
    {case DID_OK:
      { Configuration.SourceServer = WinQueryDlgItemXText(GetHwnd(), CB_SERVER);
        const xstring& source = WinQueryDlgItemXText(GetHwnd(), CB_SINKSRC);
        Configuration.Source = source.length() && !source.startsWithI("default") ? source : xstring();
        const xstring& port = WinQueryDlgItemXText(GetHwnd(), CB_PORT);
        Configuration.SourcePort = port.length() && !port.startsWithI("default") ? port : xstring();
        Configuration.SourceRate = atoi(SamplingRates[SpinButton(GetCtrl(SB_RATE)).Value()]);
        Configuration.SourceChannels = WinQueryButtonCheckstate(GetHwnd(), RB_MONO) ? 1 : 2;
      }
      break;
    }
    break;

   case UM_DISCOVER_SERVER:
    { DEBUGLOG(("LoadWizard::DlgProc:UM_DISCOVER_SERVER\n"));
      try
      { Context.GetServerInfo(ServerInfoOp);
        Sources.clear();
        Context.GetSourceInfo(SourceInfoOp);
      } catch (const PAException& ex)
      { WinSetDlgItemText(GetHwnd(), ST_STATUS, ex.GetMessage());
      }
      return 0;
    }

   case UM_UPDATE_SERVER:
    { int error = LONGFROMMP(mp1);
      DEBUGLOG(("LoadWizard::DlgProc:UM_UPDATE_SERVER %i\n", error));
      if (error)
      { WinSetDlgItemText(GetHwnd(), ST_STATUS, PAConnectException(Context.GetContext(), error).GetMessage());
        return 0;
      }
      WinSetDlgItemText(GetHwnd(), ST_STATUS, "Success");
      ComboBox cb(GetCtrl(CB_SINKSRC));
      // save old value
      const xstring& oldsink = cb.Text();
      // delete old list
      cb.DeleteAll();
      SelectedSource = -1;
      // insert new list and restore old value if reasonable.
      xstring def;
      def.sprintf("default (%s)", Server.default_sink_name.cdata());
      cb.InsertItem(def);
      if (Sources.size() != 0)
      { int defsink = -1;
        for (unsigned i = 0; i < Sources.size(); ++i)
        { PASourceInfo& source = *Sources[i];
          cb.InsertItem(source.name);
          if (SelectedSource < 0 && source.name.compareToI(oldsink) == 0)
            SelectedSource = i;
          if (defsink < 0 && source.name.compareToI(Server.default_sink_name) == 0)
            defsink = i;
        }
        cb.Select(SelectedSource+1);
        if (SelectedSource < 0)
          SelectedSource = defsink;
      }
    }
   case UM_UPDATE_PORT:
    { DEBUGLOG(("LoadWizard::DlgProc:UM_UPDATE_PORT %i\n", SelectedSource));
      ComboBox cb(GetCtrl(CB_PORT));
      // save old value
      const xstring& oldport = cb.Text();
      // delete old list
      cb.DeleteAll();
      // insert new list and restore old value if reasonable.
      xstring def;
      int selected = -1;
      if ((unsigned)SelectedSource < Sources.size())
      { PASourceInfo& source = *Sources[SelectedSource];
        if (source.active_port)
          def.sprintf("default (%s)", source.active_port->name.cdata());
        for (unsigned i = 0; i < source.ports.size(); ++i)
        { PAPortInfo& port = source.ports[i];
          cb.InsertItem(port.name);
          if (selected < 0 && port.name.compareToI(oldport) == 0)
            selected = i;
        }
      }
      cb.InsertItem(def ? def.cdata() : "default", 0);
      cb.Select(selected+1);
      return 0;
    }
  }
  return IntrospectBase::DlgProc(msg, mp1, mp2);
}
Exemplo n.º 26
0
MRESULT ConfigDialog::DlgProc(ULONG msg, MPARAM mp1, MPARAM mp2)
{
  switch (msg)
  {case WM_INITDLG:
    { MRESULT ret = IntrospectBase::DlgProc(msg, mp1, mp2);
      if (Configuration.Sink)
        PMRASSERT(WinSetDlgItemText(GetHwnd(), CB_SINKSRC, Configuration.Sink));
      if (Configuration.SinkPort)
        PMRASSERT(WinSetDlgItemText(GetHwnd(), CB_PORT, Configuration.SinkPort));
      // Set current value
      if (Configuration.SinkServer)
      { ComboBox(+GetCtrl(CB_SERVER)).Text(Configuration.SinkServer);
        PostMsg(UM_CONNECT, 0, 0);
      }
      SpinButton sb(GetCtrl(SB_MINLATENCY));
      sb.SetLimits(0, 5000, 4);
      sb.Value(Configuration.SinkMinLatency);
      sb = SpinButton(GetCtrl(SB_MAXLATENCY));
      sb.SetLimits(100, 10000, 4);
      sb.Value(Configuration.SinkMaxLatency);
      return ret;
    }

   case WM_COMMAND:
    DEBUGLOG(("ConfigDialog::DlgProc:WM_COMMAND(%i,%i, %p)\n", SHORT1FROMMP(mp1), SHORT2FROMMP(mp1), mp2));
    switch (SHORT1FROMMP(mp1))
    {case DID_OK:
      { Configuration.SinkServer = WinQueryDlgItemXText(GetHwnd(), CB_SERVER);
        const xstring& sink = WinQueryDlgItemXText(GetHwnd(), CB_SINKSRC);
        Configuration.Sink = sink.length() && !sink.startsWithI("default") ? sink : xstring();
        const xstring& port = WinQueryDlgItemXText(GetHwnd(), CB_PORT);
        Configuration.SinkPort = port.length() && !port.startsWithI("default") ? port : xstring();
        Configuration.SinkMinLatency = SpinButton(GetCtrl(SB_MINLATENCY)).Value();
        Configuration.SinkMaxLatency = SpinButton(GetCtrl(SB_MAXLATENCY)).Value();
      }
      break;
    }
    break;

   case UM_DISCOVER_SERVER:
    { DEBUGLOG(("ConfigDialog::DlgProc:UM_DISCOVER_SERVER\n"));
      try
      { Context.GetServerInfo(ServerInfoOp);
        Sinks.clear();
        Context.GetSinkInfo(SinkInfoOp);
      } catch (const PAException& ex)
      { WinSetDlgItemText(GetHwnd(), ST_STATUS, ex.GetMessage());
      }
      return 0;
    }

   case UM_UPDATE_SERVER:
    { int error = LONGFROMMP(mp1);
      DEBUGLOG(("ConfigDialog::DlgProc:UM_UPDATE_SERVER %i\n", error));
      if (error)
      { WinSetDlgItemText(GetHwnd(), ST_STATUS, PAConnectException(Context.GetContext(), error).GetMessage());
        return 0;
      }
      WinSetDlgItemText(GetHwnd(), ST_STATUS, "Success");
      ComboBox cb(GetCtrl(CB_SINKSRC));
      // save old value
      const xstring& oldsink = cb.Text();
      // delete old list
      cb.DeleteAll();
      SelectedSink = -1;
      // insert new list and restore old value if reasonable.
      xstring def;
      def.sprintf("default (%s)", Server.default_sink_name.cdata());
      cb.InsertItem(def);
      if (Sinks.size() != 0)
      { int defsink = -1;
        for (unsigned i = 0; i < Sinks.size(); ++i)
        { PASinkInfo& sink = *Sinks[i];
          cb.InsertItem(sink.name);
          if (SelectedSink < 0 && sink.name.compareToI(oldsink) == 0)
            SelectedSink = i;
          if (defsink < 0 && sink.name.compareToI(Server.default_sink_name) == 0)
            defsink = i;
        }
        cb.Select(SelectedSink+1);
        if (SelectedSink < 0)
          SelectedSink = defsink;
      }
    }
   case UM_UPDATE_PORT:
    { DEBUGLOG(("ConfigDialog::DlgProc:UM_UPDATE_PORT %i\n", SelectedSink));
      ComboBox cb(GetCtrl(CB_PORT));
      // save old value
      const xstring& oldport = cb.Text();
      // delete old list
      cb.DeleteAll();
      // insert new list and restore old value if reasonable.
      xstring def;
      int selected = -1;
      if ((unsigned)SelectedSink < Sinks.size())
      { PASinkInfo& sink = *Sinks[SelectedSink];
        if (sink.active_port)
          def.sprintf("default (%s)", sink.active_port->name.cdata());
        for (unsigned i = 0; i < sink.ports.size(); ++i)
        { PAPortInfo& port = sink.ports[i];
          cb.InsertItem(port.name);
          if (selected < 0 && port.name.compareToI(oldport) == 0)
            selected = i;
        }
      }
      cb.InsertItem(def ? def.cdata() : "default", 0);
      cb.Select(selected+1);
      return 0;
    }
  }
  return IntrospectBase::DlgProc(msg, mp1, mp2);
}
Exemplo n.º 27
0
bool CCDeviceRenderer::loadShader(CCShader *shader)
{
	GLuint vertShader, fragShader;
	
	CCText shaderPath = shader->name;
	shaderPath += ".fx";
	
    // Create shader program
	shader->program = glCreateProgram();
	
	if( !compileShader( &vertShader, GL_VERTEX_SHADER, shaderPath.buffer ) )
	{
		DEBUGLOG( "Failed to compile vertex shader." );
		glDeleteProgram( shader->program );
		shader->program = 0;
		return false;
	}
	
	if( !compileShader( &fragShader, GL_FRAGMENT_SHADER, shaderPath.buffer ) )
	{
		DEBUGLOG( "Failed to compile fragment shader." );
		glDeleteProgram( shader->program );
		shader->program = 0;
		return false;
	}
	
	DEBUG_OPENGL();
	
	// Attach shaders to program
	glAttachShader( shader->program, vertShader );
    DEBUG_OPENGL();
    
	glAttachShader( shader->program, fragShader );
    DEBUG_OPENGL();
	
    // Bind attribute locations - this needs to be done prior to linking
	glBindAttribLocation( shader->program, ATTRIB_VERTEX, "vs_position" );
	glBindAttribLocation( shader->program, ATTRIB_TEXCOORD, "vs_texCoord" );
	glBindAttribLocation( shader->program, ATTRIB_COLOUR, "vs_colour" );
	glBindAttribLocation( shader->program, ATTRIB_NORMAL, "vs_normal" );
    DEBUG_OPENGL();
	
	if( !linkProgram( shader->program ) )
	{
		DEBUGLOG( "Failed to link program." );
		if( vertShader )
		{
			glDeleteShader( vertShader );
			vertShader = 0;
		}
		
		if( fragShader )
		{
			glDeleteShader( fragShader );
			fragShader = 0;
		}
		
		if( shader->program )
		{
			glDeleteProgram( shader->program );
			shader->program = 0;
		}
		
		return false;
	}
    
    // Release vertex and fragment shaders
    if( vertShader )
	{
		glDeleteShader( vertShader );
	}
	
	if( fragShader )
	{
		glDeleteShader( fragShader );
	}
	
    return true;
}
Exemplo n.º 28
0
static int _get_num_nodes()
{
	DEBUGLOG("num_nodes = %d\n", num_nodes);
	return num_nodes;
}
bool cParserH264::Parse_SPS(uint8_t *buf, int len)
{
  cBitstream bs(buf, len*8);
  unsigned int tmp, frame_mbs_only;
  int cbpsize = -1;

  int profile_idc = bs.readBits(8);
  /* constraint_set0_flag = bs.readBits1();    */
  /* constraint_set1_flag = bs.readBits1();    */
  /* constraint_set2_flag = bs.readBits1();    */
  /* constraint_set3_flag = bs.readBits1();    */
  /* reserved             = bs.readBits(4);    */
  bs.skipBits(8);
  int level_idc = bs.readBits(8);
  unsigned int seq_parameter_set_id = bs.readGolombUE(9);

  unsigned int i = 0;
  while (h264_lev2cpbsize[i][0] != -1)
  {
    if (h264_lev2cpbsize[i][0] >= level_idc)
    {
      cbpsize = h264_lev2cpbsize[i][1];
      break;
    }
    i++;
  }
  if (cbpsize < 0)
    return false;

  memset(&m_streamData.sps[seq_parameter_set_id], 0, sizeof(h264_private::SPS));
  m_streamData.sps[seq_parameter_set_id].cbpsize = cbpsize * 125; /* Convert from kbit to bytes */

  if( profile_idc == 100 || profile_idc == 110 ||
      profile_idc == 122 || profile_idc == 244 || profile_idc == 44 ||
      profile_idc == 83 || profile_idc == 86 || profile_idc == 118 ||
      profile_idc == 128 )
  {
    int chroma_format_idc = bs.readGolombUE(9); /* chroma_format_idc              */
    if(chroma_format_idc == 3)
      bs.skipBits(1);           /* residual_colour_transform_flag */
    bs.readGolombUE();          /* bit_depth_luma - 8             */
    bs.readGolombUE();          /* bit_depth_chroma - 8           */
    bs.skipBits(1);             /* transform_bypass               */
    if (bs.readBits1())         /* seq_scaling_matrix_present     */
    {
      for (int i = 0; i < ((chroma_format_idc != 3) ? 8 : 12); i++)
      {
        if (bs.readBits1())     /* seq_scaling_list_present       */
        {
          int last = 8, next = 8, size = (i<6) ? 16 : 64;
          for (int j = 0; j < size; j++)
          {
            if (next)
              next = (last + bs.readGolombSE()) & 0xff;
            last = !next ? last: next;
          }
        }
      }
    }
  }

  int log2_max_frame_num_minus4 = bs.readGolombUE();           /* log2_max_frame_num - 4 */
  m_streamData.sps[seq_parameter_set_id].log2_max_frame_num = log2_max_frame_num_minus4 + 4;
  int pic_order_cnt_type = bs.readGolombUE(9);
  m_streamData.sps[seq_parameter_set_id].pic_order_cnt_type = pic_order_cnt_type;
  if (pic_order_cnt_type == 0)
  {
    int log2_max_pic_order_cnt_lsb_minus4 = bs.readGolombUE();         /* log2_max_poc_lsb - 4 */
    m_streamData.sps[seq_parameter_set_id].log2_max_pic_order_cnt_lsb = log2_max_pic_order_cnt_lsb_minus4 + 4;
  }
  else if (pic_order_cnt_type == 1)
  {
    m_streamData.sps[seq_parameter_set_id].delta_pic_order_always_zero_flag = bs.readBits1();
    bs.readGolombSE();         /* offset_for_non_ref_pic          */
    bs.readGolombSE();         /* offset_for_top_to_bottom_field  */
    tmp = bs.readGolombUE();   /* num_ref_frames_in_pic_order_cnt_cycle */
    for (unsigned int i = 0; i < tmp; i++)
      bs.readGolombSE();       /* offset_for_ref_frame[i]         */
  }
  else if(pic_order_cnt_type != 2)
  {
    /* Illegal poc */
    return false;
  }

  bs.readGolombUE(9);          /* ref_frames                      */
  bs.skipBits(1);             /* gaps_in_frame_num_allowed       */
  m_Width  /* mbs */ = bs.readGolombUE() + 1;
  m_Height /* mbs */ = bs.readGolombUE() + 1;
  frame_mbs_only     = bs.readBits1();
  m_streamData.sps[seq_parameter_set_id].frame_mbs_only_flag = frame_mbs_only;
  DEBUGLOG("H.264 SPS: pic_width:  %u mbs", (unsigned) m_Width);
  DEBUGLOG("H.264 SPS: pic_height: %u mbs", (unsigned) m_Height);
  DEBUGLOG("H.264 SPS: frame only flag: %d", frame_mbs_only);

  m_Width  *= 16;
  m_Height *= 16 * (2-frame_mbs_only);

  if (!frame_mbs_only)
  {
    if (bs.readBits1())     /* mb_adaptive_frame_field_flag */
      DEBUGLOG("H.264 SPS: MBAFF");
  }
  bs.skipBits(1);           /* direct_8x8_inference_flag    */
  if (bs.readBits1())       /* frame_cropping_flag */
  {
    uint32_t crop_left   = bs.readGolombUE();
    uint32_t crop_right  = bs.readGolombUE();
    uint32_t crop_top    = bs.readGolombUE();
    uint32_t crop_bottom = bs.readGolombUE();
    DEBUGLOG("H.264 SPS: cropping %d %d %d %d", crop_left, crop_top, crop_right, crop_bottom);

    m_Width -= 2*(crop_left + crop_right);
    if (frame_mbs_only)
      m_Height -= 2*(crop_top + crop_bottom);
    else
      m_Height -= 4*(crop_top + crop_bottom);
  }

  /* VUI parameters */
  m_PixelAspect.num = 0;
  if (bs.readBits1())    /* vui_parameters_present flag */
  {
    if (bs.readBits1())  /* aspect_ratio_info_present */
    {
      uint32_t aspect_ratio_idc = bs.readBits(8);
      DEBUGLOG("H.264 SPS: aspect_ratio_idc %d", aspect_ratio_idc);

      if (aspect_ratio_idc == 255 /* Extended_SAR */)
      {
        m_PixelAspect.num = bs.readBits(16); /* sar_width */
        m_PixelAspect.den = bs.readBits(16); /* sar_height */
        DEBUGLOG("H.264 SPS: -> sar %dx%d", m_PixelAspect.num, m_PixelAspect.den);
      }
      else
      {
        static const mpeg_rational_t aspect_ratios[] =
        { /* page 213: */
          /* 0: unknown */
          {0, 1},
          /* 1...16: */
          { 1,  1}, {12, 11}, {10, 11}, {16, 11}, { 40, 33}, {24, 11}, {20, 11}, {32, 11},
          {80, 33}, {18, 11}, {15, 11}, {64, 33}, {160, 99}, { 4,  3}, { 3,  2}, { 2,  1}
        };

        if (aspect_ratio_idc < sizeof(aspect_ratios)/sizeof(aspect_ratios[0]))
        {
          memcpy(&m_PixelAspect, &aspect_ratios[aspect_ratio_idc], sizeof(mpeg_rational_t));
          DEBUGLOG("H.264 SPS: PAR %d / %d", m_PixelAspect.num, m_PixelAspect.den);
        }
        else
        {
          DEBUGLOG("H.264 SPS: aspect_ratio_idc out of range !");
        }
      }
    }
    if (bs.readBits1()) // overscan
    {
      bs.readBits1(); // overscan_appropriate_flag
    }
    if (bs.readBits1()) // video_signal_type_present_flag
    {
      bs.readBits(3); // video_format
      bs.readBits1(); // video_full_range_flag
      if (bs.readBits1()) // colour_description_present_flag
      {
        bs.readBits(8); // colour_primaries
        bs.readBits(8); // transfer_characteristics
        bs.readBits(8); // matrix_coefficients
      }
    }

    if (bs.readBits1()) // chroma_loc_info_present_flag
    {
      bs.readGolombUE(); // chroma_sample_loc_type_top_field
      bs.readGolombUE(); // chroma_sample_loc_type_bottom_field
    }

    if (bs.readBits1()) // timing_info_present_flag
    {
//      uint32_t num_units_in_tick = bs.readBits(32);
//      uint32_t time_scale = bs.readBits(32);
//      int fixed_frame_rate = bs.readBits1();
//      if (num_units_in_tick > 0)
//        m_FPS = time_scale / (num_units_in_tick * 2);
    }
  }

  DEBUGLOG("H.264 SPS: -> video size %dx%d, aspect %d:%d", m_Width, m_Height, m_PixelAspect.num, m_PixelAspect.den);
  return true;
}
Exemplo n.º 30
0
cLiveReceiver::~cLiveReceiver()
{
  DEBUGLOG("Killing live receiver");
}